package com.buydeem.share;

/**
 * wait和notify死锁
 *
 * @author zengchao
 * @date 2021-07-21 13:57:57
 * @since 1.0
 */
public class WaitNotifyDemo5 {
    static final Object LOCK1 = new Object();
    static final Object LOCK2 = new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            synchronized (LOCK1) {
                synchronized (LOCK2) {
                    try {
                        System.out.println("线程t1调用wait");
                        LOCK1.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        t1.setName("t1");
        t1.start();

        Thread.sleep(1000);

        Thread t2 = new Thread(() ->{
            synchronized (LOCK1){
                synchronized (LOCK2){
                    System.out.println("线程t2执行");
                }
            }
        });
        t2.setName("t2");
        t2.start();

        t1.join();
        t2.join();
    }
}
